package com.czy;

import com.czy.utils.BCryptPasswordUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class SecurityPassword {


    @Test
    public void password(){
        // 1. 创建编码器（可自定义强度，默认10）
        PasswordEncoder encoder = new BCryptPasswordEncoder(12);

        // 2. 加密密码
        String rawPassword = "123456";
        String encodedPassword = encoder.encode(rawPassword);
        System.out.println("加密结果: " + encodedPassword);
        // 示例输出: $2a$12$XmR7i6zGJv2oOJfd2vR6E.6T5W8nYb5JkLd7Nc1wVzqgKj3lLm7S

        // 3. 验证密码
        boolean isMatch = encoder.matches("1234", encodedPassword);
        System.out.println("验证结果: " + isMatch); // true

        System.out.println(BCryptPasswordUtils.encryptedPasswords("123456"));
    }

}
